package com.xiaotu.code.system;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 同步任务包装类.
 * 
 * 供同步任务使用，见com.iris.scm.system.task.BaseTask
 * 
 * @author chenxiangrong
 * 
 */
public class SyncTaskWrap implements Serializable, Runnable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7246274729604148419L;
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	private BaseTask task;
	private Map<String, Date> lockContainer;

	public SyncTaskWrap(Map<String, Date> lockContainer, BaseTask task) {
		super();
		this.lockContainer = lockContainer;
		this.task = task;
	}

	@Override
	public void run() {

		try {

			logger.info(String.format("SyncTaskWrap task:进入%s执行", task.getTaskName()));
			task.run();
			logger.info(String.format("SyncTaskWrap task:%s执行完毕", task.getTaskName()));
			// 将锁的时间置空，表示释放锁
			lockContainer.put(task.getTaskName(), null);
		} catch (Exception e) {
			logger.error(String.format("SyncTaskWrap运行任务%s错误", task.getTaskName()), e);
			// 将锁的时间置空，表示释放锁
			lockContainer.put(task.getTaskName(), null);
		}
	}

}
